home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / gestalt.zip / GESTALT.PAS < prev    next >
Pascal/Delphi Source File  |  1988-12-06  |  3KB  |  102 lines

  1. PROGRAM TestSim;
  2.   {Test SIMIL_P.ASM string similarity function.
  3.    See SIMIL_C.ASM for detailed explanation,
  4.    or look at the original article in Dr. Dobbs Journal.
  5.    (You mean, you don't subscribe to Dr. Dobbs?  Sigh ...)
  6.  
  7.    Works just fine with Turbo Pascal v3.0.
  8.    I don't HAVE v4.0, etc., so you're on your own if you want
  9.    to port it.
  10.  
  11.    David Kirschbaum
  12.    Toad Hall
  13.    kirsch@braggvax.ARPA
  14.   }
  15.  
  16. { Simil procedure requires these internally:}
  17. TYPE
  18.   array25 = ARRAY[1..25] OF INTEGER;
  19. VAR
  20.   ststr1L,
  21.   ststr1R,
  22.   ststr2L,
  23.   ststr2R : array25;
  24.   stcknum,
  25.   score,
  26.   total,
  27.   cL1,
  28.   cR1,
  29.   cL2,
  30.   cR2,
  31.   s2ed : INTEGER;
  32.  
  33. FUNCTION Simil (VAR Str1, Str2) : INTEGER;
  34.   {We're assuming Str1 and Str2 are in fact Pascal strings.
  35.    Type is immaterial, just so long as the first byte is the length byte.
  36.   }
  37.   VAR  result : INTEGER;
  38.   BEGIN
  39.     {$I SIMIL_P.OBJ}
  40.     Simil := result;         {return function}
  41.   END;  {of Simil}
  42.  
  43.  
  44. {Test program needs this for passing parms, etc.}
  45. TYPE
  46.   Str128 = STRING[128];
  47.  
  48.  
  49. {Show that Simil will work with passed variables.
  50.  (This works just as well if you use (VAR S21,S22 : Str128).
  51. }
  52. PROCEDURE Do_Simil_Var(S21,S22 : Str128);
  53.   VAR
  54.     i     : INTEGER;
  55.   BEGIN
  56.     Writeln('Testing Simil function with passed variables...');
  57.     S21 := '[20char test string]';
  58.     S22 := S21;
  59.     FOR i := 1 TO LENGTH(S21) DO BEGIN
  60.       Writeln(S21, S22, '  Similarity: ', Simil(S21,S22):3, '%');
  61.       S22[i] := '.';                    {blank out a char in String 2}
  62.     END;
  63.     Writeln(S21, S22, '  Similarity: ', Simil(S21,S22):3, '%');
  64.   END;  {of Do_Simil_Var}
  65.  
  66.  
  67. {Show that Simil will work with local variables as well as globals}
  68. PROCEDURE Do_Simil_Local;
  69.   VAR
  70.     S31,S32 : Str128;
  71.     i     : INTEGER;
  72.   BEGIN
  73.     Writeln('Testing Simil function with local variables...');
  74.     S31 := '[20char test string]';
  75.     S32 := S31;
  76.     FOR i := 1 TO LENGTH(S31) DO BEGIN
  77.       Writeln(S31, S32, '  Similarity: ', Simil(S31,S32):3, '%');
  78.       S32[i] := '.';                    {blank out a char in String 2}
  79.     END;
  80.     Writeln(S31, S32, '  Similarity: ', Simil(S31,S32):3, '%');
  81.   END;  {of Do_Simil_Local}
  82.  
  83.  
  84. {Required for our test program}
  85. VAR
  86.   S1,S2 : Str128;
  87.   i     : INTEGER;
  88.  
  89.  
  90. BEGIN  {main}
  91.   Writeln('Testing Simil function with global variables...');
  92.   S1 := '[20char test string]';
  93.   S2 := S1;
  94.   FOR i := 1 TO LENGTH(S1) DO BEGIN
  95.     Writeln(S1, S2, '  Similarity: ', Simil(S1,S2):3, '%');
  96.     S2[i] := '.';                       {blank out a char in String 2}
  97.   END;
  98.   Writeln(S1, S2, '  Similarity: ', Simil(S1,S2):3, '%');
  99.   Do_Simil_Var(S1,S2);                  {Test Simil with passed variables}
  100.   Do_Simil_Local;                       {Test Simil with local variables}
  101. END.
  102.